package org.lgh.wallet.common;

import java.util.HashMap;

/**
 * 交易类型枚举
 * ('充值','转账','消费','退款')
 * @author wei-xhh
 * @date 2023-02-27
 */
public enum TradeTypeEnum {

    RECHARGE("充值", 1),
    TRANSFER("转账", 2),
    CONSUME("消费", 3),
    DRAW_BACK("退款", 4);
    TradeTypeEnum(String key, Integer value){
        this.key = key;
        this.value = value;
    }
    private String key;
    private Integer value;

    private static HashMap<Integer, TradeTypeEnum> valueMap = new HashMap<Integer, TradeTypeEnum>();
    //静态代码块
    static{
        for (TradeTypeEnum item : TradeTypeEnum.values()) {
            valueMap.put(item.getValue(), item);
        }
    }
    public String getKey() {
        return key;
    }
    public void setKey(String key) {
        this.key = key;
    }
    public Integer getValue() {
        return value;
    }
    public void setValue(Integer value) {
        this.value = value;
    }
    // 前台传进来的值通过这个方法来转换为类型
    public static TradeTypeEnum getByValue(int value) {
        TradeTypeEnum result = valueMap.get(value);
        if(result == null) {
            throw new IllegalArgumentException("No element matches " + value);
        }
        return result;
    }
}
